const QQMapWX = require('qqmap-wx-jssdk.min.js');
const qqmapsdk = new QQMapWX({
  key: 'FQABZ-RETKP-324D7-LWHOJ-4UIVJ-PPF7I' // 必填
});

var getmap = function (adress,callback){
  qqmapsdk.getSuggestion({
    //获取输入框值并设置keyword参数
    keyword: adress, //用户输入的关键词，可设置固定值,如keyword:'KFC'
    policy: 1,
    // address_format: "short",
    success: function (res) {//搜索成功后的回调
      var sug = [];
      for (var i = 0; i < res.data.length; i++) {
        sug.push({ // 获取返回结果，放到sug数组中
          title: res.data[i].title,
          id: res.data[i].id,
          addr: res.data[i].address,
          city: res.data[i].city,
          district: res.data[i].district,
          latitude: res.data[i].location.lat,
          longitude: res.data[i].location.lng
        });
      }
      callback(sug)
    },
    fail: function (error) {
      console.error(error);
    }
  });
}

module.exports = {
  getmap: getmap
}